package com.siwei.infoextract.wrapper.featureextract;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneFeatureVector{
	private String innerText;
	private String tagName;
	private String prevSiblingInnerText;

	public static Pattern phonePattern = Pattern.compile("([\\d]{1,4}-){0,2}[\\d]{5,8}");

	public String getInnerText() {
		return innerText;
	}

	public void setInnerText(String innerText) {
		this.innerText = innerText;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	public String getPrevSiblingInnerText() {
		return prevSiblingInnerText;
	}

	public void setPrevSiblingInnerText(String prevSiblingInnerText) {
		this.prevSiblingInnerText = prevSiblingInnerText;
	}

	public boolean isPhonePattern() {
		if (innerText == null || innerText.trim().equals("")) {
			return false;
		}

		innerText = innerText.replaceAll("$phone", "");
		innerText = innerText.replaceAll("$/phone", "");

		Matcher matcher = phonePattern.matcher(innerText);

		if (matcher.find()) {
			return true;
		} else {
			return false;
		}
	}
	
	public static void main(String[] args) {
		String phone1 = "1234567";
		String phone2 = "010-1234567";
		String phone3 = "086-0567-1234567";
		
		Matcher matcher = phonePattern.matcher(phone1);
		if (matcher.find()) {
			System.out.println("phone1 matched");
		}
		
		matcher = phonePattern.matcher(phone2);
		if (matcher.find()) {
			System.out.println("phone2 matched");
		}

		matcher = phonePattern.matcher(phone3);
		if (matcher.find()) {
			System.out.println("phone3 matched");
		}
	}
	
}
